package com.yk.ykmessagesdk.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.yk.ykmessagesdk.callback.PermissionListener;

import java.util.List;


public class PermissionUtils {
    private static PermissionListener listener;
    public static final String[] SDK_PERMISSIONS = {
            "android.permission.SEND_SMS",
            "android.permission.READ_SMS", "android.permission.READ_PHONE_STATE"};

    protected static void requestPermission(Context context, String[] permissions, PermissionListener permissionListener){
        listener = permissionListener;
        XXPermissions.with(context).permission(permissions).request(new OnPermissionCallback() {
            @Override
            public void onGranted(@NonNull List<String> list, boolean allGranted) {
                listener.onGranted(list, allGranted);
                LogUtils.logger("requestPermission onGranted allGranted:"+allGranted);
            }

            @Override
            public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {
                listener.onGranted(permissions, doNotAskAgain);
                LogUtils.logger("requestPermission onDenied doNotAskAgain:"+doNotAskAgain);
            }
        });

    }

    protected static boolean checkAllPermissions(Context context,String ...permission){
        return XXPermissions.isGranted(context,permission);
    }


    protected static boolean checkPermission(Context context,String permission){
        return XXPermissions.isGranted(context,permission);
    }

    protected static boolean checkSendMsgPermission(Context context){
        return XXPermissions.isGranted(context,SDK_PERMISSIONS[0]);
    }
}
